package Main;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;

/**
 *
 * @author Emmanuel
 */
public class NiveauArcade extends Niveau {
    
    private static final int DIST_MIN=500;	//300
    
    private Random rand;
    
    public NiveauArcade() {
        rand=new Random(System.currentTimeMillis());
        this.lesObstacles=new LinkedList();
        this.lesObstacles.add(new BasicObstacle(new Position(1200, 0), 150, 100));
        Obstacle tmp=ajouterObstacles();
        for(int i=0;i<5;i++) {
            ajouterObstacles();
        }
    }

    @Override
    public synchronized void addObstacle(Obstacle o) {

    }

    @Override
    public Obstacle getNext() {
       if(!lesObstacles.isEmpty()) {
            return lesObstacles.get(0);
        }
        return null;
    }

    @Override
    public List getObstacle() {
        return this.lesObstacles;
    }

    @Override
    public void removeObstacle() {
        if(lesObstacles.size()>0) {
            lesObstacles.remove(0);
            ajouterObstacles();
        }
    }

    private Obstacle ajouterObstacles() {
        
        int x=0;
        Obstacle o;
        
        try {
            Obstacle tmp=lesObstacles.getLast();
            x=tmp.getPosition().getX()+tmp.getSizeX();
        } catch (Exception e) {}
        
        int r=rand.nextInt(200);
        
        switch(rand.nextInt(3)) {
            case 0:
                o=new BasicObstacle(new Position(x+r+DIST_MIN, 0), 150, 100);
                break;
            case 1:
                o=new AirObstacle(new Position(x+r+DIST_MIN, 150), 150, 100);
                break;
            case 2:
                o=new BasicObstacle(new Position(x+r+DIST_MIN, 0), 150, 150);
                break;
            default:
                o=new BasicObstacle(new Position(x+r+DIST_MIN, 0), 150, 100);
                break;
        }
        
        lesObstacles.add(o);
        
        return o;
    }
}
